package com.secsbrain.deploy.client.iface;

import java.util.List;

import com.secsbrain.deploy.client.model.BatchBuildParam;
import com.secsbrain.deploy.client.model.BuildParam;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.secsbrain.common.ResponseVo;
import com.secsbrain.deploy.client.model.BatchBuildResult;
import com.secsbrain.deploy.client.model.BuildLog;
import com.secsbrain.deploy.client.model.BuildRecord;
import com.secsbrain.deploy.client.model.HealthDto;
import com.secsbrain.deploy.client.model.JobNameBuildParam;

/**
 * 发布相关服务
 *
 * @author zhaoyi
 */
@FeignClient(value = "service-deploy")
public interface DeployService {
	
	/**
     * 功能描述: <br>
     * 构建准备（审批通过创建记录，不执行构建）
     *
     * @param  buildParam   构建参数
     * @return 构建ID
     */
    @RequestMapping(value = "/deployservice/buildPre", method = RequestMethod.POST)
	ResponseVo<Long> buildPre(@RequestBody BuildParam buildParam);
	
	/**
     * 功能描述: <br>
     * 执行构建
     *
     * @param  buildParam   构建参数
     * @return 构建ID
     */
    @RequestMapping(value = "/deployservice/build", method = RequestMethod.POST)
	ResponseVo<Long> build(@RequestBody BuildParam buildParam);
    
    /**
     * 功能描述: <br>
     * 批量执行构建
     *
     * @param  batchBuildParam   批量构建参数
     * @return 批量构建结果
     */
    @RequestMapping(value = "/deployservice/buildBatch", method = RequestMethod.POST)
    ResponseVo<BatchBuildResult> buildBatch(@RequestBody BatchBuildParam batchBuildParam);
    
    /**
     * 功能描述: <br>
     * 直接通过jobName执行构建
     *
     * @param  jobNameBuildParam   jenkins job名称
     * @return  
     */
    @RequestMapping(value = "/deployservice/buildByJobName", method = RequestMethod.POST)
	ResponseVo<?> buildByJobName(@RequestBody JobNameBuildParam jobNameBuildParam);
    
    /**
     * 功能描述: <br>
     * 获取构建日志
     *
     * @param  buildId   构建ID
     * @return
     */
    @RequestMapping(value = "/deployservice/getBuildLog", method = RequestMethod.GET)
    ResponseVo<BuildLog> getBuildLog(@RequestParam("buildId") Long buildId,@RequestParam("start") Long start,@RequestParam("env") String env);
    
    /**
     * 功能描述: <br>
     * 通过构建ID获取构建记录
     *
     * @param  buildId   构建ID
     * @return
     */
    @RequestMapping(value = "/deployservice/queryBuildRecordByBuildId", method = RequestMethod.GET)
    ResponseVo<BuildRecord> queryBuildRecordByBuildId(@RequestParam("buildId") Long buildId,@RequestParam("env") String env);
    
    /**
     * 功能描述: <br>
     * 通过批次ID获取应用构建记录列表
     *
     * @param  batchId   应用ID
     * @return
     */
    @RequestMapping(value = "/deployservice/queryBuildListByBatchId", method = RequestMethod.GET)
    ResponseVo<List<BuildRecord>> queryBuildListByBatchId(@RequestParam("batchId") Long batchId,@RequestParam("env") String env);
    
    /**
     * 功能描述: <br>
     * 通过应用ID获取应用构建记录列表（分页查询）
     *
     * @param  appId    应用ID
     * @param  envName  环境名称
     * @param  page     页码
     * @param  limit    条数
     * 
     * @return
     */
    @RequestMapping(value = "/deployservice/queryBuildListByAppId", method = RequestMethod.GET)
    ResponseVo<List<BuildRecord>> queryBuildListByAppId(@RequestParam("appId") Long appId,@RequestParam("envName") String envName,@RequestParam("page") Integer page, @RequestParam("limit") Integer limit);
    
    /**
     * 功能描述: <br>
     * 获取应用构建记录列表（分页查询）
     *
     * @param  page        页码
     * @param  limit       条数
     * @param  sortBy      排序字段
     * @param  descending  排序方式
     * 
     * @param   appName    应用名称
     * @param   envName    环境名称
     * @param   branchName 分支名称
     * @param   startDate  开始时间
     * @param   endDate    结束时间
     * @param   createName 创建人
     * 
     * @return
     */
    @RequestMapping(value = "/deployservice/queryAllBuildList", method = RequestMethod.GET)
    ResponseVo<List<BuildRecord>> queryAllBuildList(@RequestParam("page") Integer page, @RequestParam("limit") Integer limit,@RequestParam("sortBy") String sortBy,
            @RequestParam(value = "descending") String descending,@RequestParam(value = "appName") String appName,
            @RequestParam(value = "envName") String envName,@RequestParam(value = "branchName") String branchName,
            @RequestParam(value = "startDate") String startDate,@RequestParam(value = "endDate") String endDate,
            @RequestParam(value = "status", required = false) Integer status,@RequestParam(value = "createName") String createName);
 
    /**
     * 功能描述: <br>
     * 通过分组ID、环境获取应用构建记录列表
     *
     * @param  groupId   分组ID
     * @return
     */
    @RequestMapping(value = "/deployservice/queryBuildListByGroupId", method = RequestMethod.GET)
    ResponseVo<List<BuildRecord>> queryBuildListByGroupId(@RequestParam("groupId") Long groupId,@RequestParam("envName") String envName);
   
    /**
     * 功能描述: <br>
     * 灰度切流
     *
     * @param  groupId   分组ID
     * @param  percent   百分比
     * @return
     */
    @RequestMapping(value = "/deployservice/percentRelease", method = RequestMethod.GET)
    ResponseVo<Integer> percentRelease(@RequestParam("groupId") Long groupId,@RequestParam("percent") Integer percent);
    
    /**
     * 功能描述: <br>
     * 健康检查
     *
     * @param  healthDto   健康检查对象
     * @return  
     */
    @RequestMapping(value = "/deployservice/healthCheck", method = RequestMethod.POST)
	ResponseVo<?> healthCheck(@RequestBody HealthDto healthDto);
    
    /**
     * 功能描述: <br>
     * 上线服务
     *
     * @param appId  应用ID
     * @param host   主机名
     * @return
     */
    @RequestMapping(value = "/deployservice/serverUp", method = RequestMethod.GET)
    ResponseVo<?> serverUp(@RequestParam("appId") Long appId,@RequestParam("host") String host);

}
